package com.ymttest.database.sqlwapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtRefundBill;
import com.ymttest.database.model.YmtRefundProduct;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name : YmtUserValidateWapper.java
 * @Author : zhouyi
 * @Date : 2015年3月30日
 * @Copyright : 洋码头
 ************************************************************************************/
public class YmtRefundWapper {
	SqlManager manage;

	public YmtRefundWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	/**
	 * 根据订单号查询退款申请单
	 * 
	 * @param Map
	 * @return List<YmtRefundBill>
	 * @throws InterruptedException
	 */
	public List<YmtRefundBill> selectRefundBill(Map m)
			throws InterruptedException {
		List<YmtRefundBill> ymtRefundBills = new ArrayList<YmtRefundBill>();
		ymtRefundBills = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtRefundBillMapper.selectRefundBill",
						m);
		return ymtRefundBills;
	}

	/**
	 * 根据订单号查询退款申请单 退款的商品
	 * 
	 * @param Map
	 * @return List<YmtRefundProduct>
	 * @throws InterruptedException
	 */
	public List<YmtRefundProduct> selectRefundProduct(Map m)
			throws InterruptedException {
		List<YmtRefundProduct> ymtRefundProducts = new ArrayList<YmtRefundProduct>();
		ymtRefundProducts = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtRefundProductMapper.selectRefundProduct",
						m);
		return ymtRefundProducts;
	}
	
	/**
	 * 根据退款单号查询退款的商品信息
	 * 
	 * @param Map
	 * @return List<YmtRefundProduct>
	 * @throws InterruptedException
	 */
	public List<YmtRefundProduct> selectRefundProductByRefundBillNo(String refundBillNo)
			throws InterruptedException {
		Map m = new HashMap();
		m.put("refundBillNo", refundBillNo);
		List<YmtRefundProduct> ymtRefundProducts = new ArrayList<YmtRefundProduct>();
		ymtRefundProducts = manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtRefundProductMapper.selectRefundProductByRefundBillNo",
						m);
		return ymtRefundProducts;
	}

	/**
	 * @author songyefeng
	 * @date 2016-07-15
	 * @param m
	 * @return
	 */
	public List<Map> selectRefundInfo(Map m) {
		return manage
				.getSelectResults(
						"com.ymttest.database.mapping.YmtRefundBillMapper.selectRefundInfo",
						m);
	}
	
	/**
	 * 
	 * @param queryField 查询的字段
	 * @param joinCondition 连表查询
	 * @param queryCondition 查询条件
	 * @return
	 */
	public List<Map> selectRefundBill2(String queryField, String joinCondition, String queryCondition) {
		Map m = new HashMap();
		if(null != queryField && !"".equals(queryField)){
			m.put("queryField", queryField);
		}
		if(null != joinCondition && !"".equals(joinCondition)){
			m.put("joinCondition", joinCondition);
		}
		if(null != queryCondition && !"".equals(joinCondition)){
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.YmtRefundBillMapper.selectRefundBill2", m);
	}

	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String args[]) {
		Map map = new HashMap();
		map.put("orderId", 105913845);
		map.put("catalogId", "d2f27f22-48e7-497f-a34f-d5246e21dee9");
		System.out.println(new YmtRefundWapper().selectRefundBill2("refundbillno", null, "orderid=105308550"));
	}
}
